package com.zhuhai.entity;


import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Set;

/**
 * 单项一对多
 */
@Entity
@Table(name="orders")
public class Order {

    @Id
    @Column(length = 40)
    private String id;        //订单ID
    @Column(nullable = false)
    private BigDecimal amount;    //总价
    @OneToMany(cascade= CascadeType.ALL,fetch= FetchType.LAZY)//级联保存、更新、删除、刷新;延迟加载
    @JoinColumn(name="order_id")//在OrderItem表增加一个外键列来实现一对多的单向关联,使用第三张表维护时，不需要
    private Set<OrderItem> orderItems;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

   public Set<OrderItem> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(Set<OrderItem> orderItems) {
        this.orderItems = orderItems;
    }
}
